const markdown = require('markdown-it');
const hljs = require('highlight.js');

function markLoader(src) {
  const md = markdown({
    html: true,
    typographer: true,
    highlight: function (str, lang) {
      if (lang && hljs.getLanguage(lang)) {
        try {
          return '<pre class="hljs"><code>' +
                 hljs.highlight(lang, str, true).value +
                 '</code></pre>';
        } catch (__) {}
      }
  
      return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
    }
  });
  const html = md.render(src);

  return (
    '<template>\n'
    + `<div class="markdown markdown-body">${html}</div>\n`
    + '</template>\n'
  );
}
module.exports = markLoader;
